<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新增机场信息</title>
    <style>
        body {
            background-color: #f8f9fa;
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
        }
        .container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            padding: 20px;
            max-width: 500px;
            margin: 0 auto;
        }
        h1 {
            text-align: center;
            color: #343a40;
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-top: 10px;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 8px;
            margin-top: 5px;
            border: 1px solid #ced4da;
            border-radius: 4px;
        }
        button {
            margin-top: 15px;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .cancel-btn {
            background-color: #6c757d;
            color: white;
        }
        .submit-btn {
            background-color: #007bff;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>新增机场信息</h1>
        <form id="airport-form">
            <label for="code">机场代码:</label>
            <input type="text" id="code" required><br>
            
            <label for="name">机场名称:</label>
            <input type="text" id="name" required><br>
            
            <label for="city">所在城市:</label>
            <input type="text" id="city" required><br>

            <label for="country">所在国家:</label>
            <input type="text" id="country"><br>

            <label for="tz">时区:</label>
            <input type="text" id="tz"><br>
            
            <button type="submit" class="submit-btn">保存</button>
            <button type="button" onclick="cancelAdd()" class="cancel-btn">取消</button>
        </form>
    </div>

    <script>
        document.getElementById('airport-form').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = {
                code: document.getElementById('code').value,
                name: document.getElementById('name').value,
                city: document.getElementById('city').value,
                country: document.getElementById('country').value,
                tz: document.getElementById('tz').value
            };

            fetch('/api/airports', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(formData)
            })
            .then(() => {
                alert('机场信息已新增');
                window.location.href = '/flights.html';
            })
            .catch(error => console.error('Error adding airport:', error));
        });

        // 取消按钮逻辑
        function cancelAdd() {
            window.location.href = '/flights.html'; // 返回航班列表页面
        }
    </script>
</body>
</html>